package com.yc.psychologicalconsultant.service.impl;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.psychologicalconsultant.dao.DigitalPeopleDAO;
import com.yc.psychologicalconsultant.pojo.DigitalPeople;
import com.yc.psychologicalconsultant.service.DigitalPeopleService;
import com.yc.psychologicalconsultant.vo.Text;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DigitalPeopleServiceImpl extends ServiceImpl<DigitalPeopleDAO, DigitalPeople> implements DigitalPeopleService {
    @Autowired
    private DigitalPeopleDAO digitalPeopleDAO;

    @Resource
    private RedisTemplate redisTemplate;

    @Override
    public List<DigitalPeople> getDigitalPeopleList() {
        List<DigitalPeople> list= digitalPeopleDAO.getDigitalPeopleList();
        return list;
    }

    @Override
    public List<Text> getChatHistory(String name, String dialogUser) {
        ArrayList<Text> chatHistory = (ArrayList<Text>) redisTemplate.opsForValue().get(generateRedisKey(name,dialogUser));
        return chatHistory;
    }

    // 用于生成redis中的key
    private String generateRedisKey(String name, String dialogUser) {
        return name + "+chatHistory:" + dialogUser;
    }
}
